package com.yinp.proapp.module.task.activity;

import android.content.Context;
import android.graphics.Color;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;

import com.yinp.proapp.R;
import com.yinp.proapp.base.activity.AppBaseActivity;
import com.yinp.proapp.databinding.ActivityAddLabelBinding;
import com.yinp.proapp.utils.StatusBarUtil;
import com.yinp.proapp.view.viewpager2.SimplePagerTitlePictureView;
import com.yinp.proapp.view.viewpager2.ViewPager2Utils;

import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: yinp
 * @Date: 2021/9/1
 * @Description:添加标签
 */
public class AddLabelActivity extends AppBaseActivity<ActivityAddLabelBinding> {
    @Override
    protected void initViews() {
        setStatusBarHeight(StatusBarUtil.getStatusBarHeight(mContext));
        initClick(bd.header.headerBackImg);
        initIndicator();
    }

    private void initIndicator() {
//        todayUndeterminedFragment = TodayUndeterminedFragment.getInstance();
//        labelFragment = LabelFragment.getInstance();
//        fragments.put(0, todayUndeterminedFragment);
//        fragments.put(1, labelFragment);
//        bd.materialViewPager.setAdapter(ViewPager2Utils.getAdapter(this, fragments));

        List<String> titleList = new ArrayList<>(Arrays.asList("今日待做", "标签"));
        bd.materialIndicator.setBackgroundColor(Color.WHITE);
        CommonNavigator commonNavigator7 = new CommonNavigator(mContext);
        commonNavigator7.setAdjustMode(true);
        commonNavigator7.setAdapter(new CommonNavigatorAdapter() {
            @Override
            public int getCount() {
                return titleList == null ? 0 : titleList.size();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {
                SimplePagerTitlePictureView simplePagerTitleView = new SimplePagerTitlePictureView(context);
                simplePagerTitleView.setText(titleList.get(index));
                simplePagerTitleView.setNormalColor(getResources().getColor(R.color.b8b8b8));
                simplePagerTitleView.setTextSize(16);
                switch (index) {
                    case 0:
                        simplePagerTitleView.setmNormalDrawable(R.mipmap.task);
                        simplePagerTitleView.setmSelectedDrawable(R.mipmap.task_s);
                        break;
                    case 1:
                        simplePagerTitleView.setmNormalDrawable(R.mipmap.label);
                        simplePagerTitleView.setmSelectedDrawable(R.mipmap.label_s);
                        break;
                }
                simplePagerTitleView.setSelectedColor(getResources().getColor(R.color.ff4d4d));
                simplePagerTitleView.setOnClickListener(v -> bd.materialViewPager.setCurrentItem(index));
                return simplePagerTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                LinePagerIndicator indicator = new LinePagerIndicator(context);
                indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
                indicator.setLineHeight(UIUtil.dip2px(context, 0));
                indicator.setLineWidth(UIUtil.dip2px(context, 56));
                indicator.setRoundRadius(UIUtil.dip2px(context, 3));
                indicator.setStartInterpolator(new AccelerateInterpolator());
                indicator.setEndInterpolator(new DecelerateInterpolator(2.0f));
                indicator.setColors(getResources().getColor(R.color.fafafa));
                return indicator;
            }
        });
        bd.materialIndicator.setNavigator(commonNavigator7);
        ViewPager2Utils.bind(bd.materialIndicator, bd.materialViewPager);
    }

    @Override
    protected void onDestroy() {
        ViewPager2Utils.unBind(bd.materialViewPager);
        super.onDestroy();
    }
}